package com.zudada.servermain.controller.portmanage;

import com.zudada.servermain.POJO.DTO.PortFacilityAddDTO;
import com.zudada.servermain.POJO.DTO.PortFacilityDeleteDTO;
import com.zudada.servermain.POJO.DTO.PortFacilityQueryDTO;
import com.zudada.servermain.POJO.DTO.PortFacilityUpdateDTO;
import com.zudada.servermain.POJO.VO.PortFacilityVO;
import com.zudada.servermain.POJO.enums.Result;
import com.zudada.servermain.Service.PortFacilityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@RestController
@RequestMapping("/port-facility")
@Api(tags="港口设施操作接口")
public class PortFacilityController {

    @Autowired
    private  PortFacilityService portFacilityService;

    /**
     * 添加港口设施
     */
    //遇到的问题：josn不能正常解析，可以做到只能添加到存在的港口，不能查重校验，id添加的是uuid
    @PostMapping("/add")
    @ApiOperation("添加港口设施")
    public Result addPortFacility(@Valid @RequestBody PortFacilityAddDTO dto) {
        boolean success = portFacilityService.addPortFacility(dto);
        if (success) {
            return Result.success("港口设施添加成功");
        } else {
            return Result.error("港口设施添加失败");
        }
    }

    /**
     * 删除港口设施
     */
    //未处理异常
    @DeleteMapping("/delete")
    @ApiOperation("删除港口设施")
    public Result delPortFacility(@RequestBody PortFacilityDeleteDTO deleteDTO){
        portFacilityService.deleteById(deleteDTO.getFacilityId());
        return Result.success("港口设施删除成功");
    }

    /**
     * 修改港口设施
     * @param dto
     * @return
     */
    //异常处理
    @PutMapping("/update")
    @ApiOperation("修改港口设施接口")
    public Result<String> updatePortFacility(@Valid @RequestBody PortFacilityUpdateDTO dto){
        boolean result= portFacilityService.updatePortFacility(dto);
        if(result){
            return Result.success("港口设施修改成功");
        }else {
            return Result.error("港口设施修改失败");
        }
    }

    /**
     * 条件查询港口设施列表
     */
    //单个条件查询？
    @GetMapping("/list")
    @ApiOperation("查询港口信息")
    public List<PortFacilityVO> listPortFacilities(@RequestBody PortFacilityQueryDTO queryDTO) {
        return portFacilityService.listPortFacilities(queryDTO);
    }


}
